﻿@model DslamPort.Models.DslamPortModel
<div class="container_12">
    <div class="grid_12">
        <div class="module">
            @using (Html.BeginForm("FindDslamPort", "DslamPortftth", FormMethod.Post, new { id = "FindDslamPort" }))
            {
                <h2 align="right">
                    <span><a href="#" onclick="document.getElementById('FindDslamPort').submit()">Quay lại</a></span></h2>
                <input type="hidden" name="xa_phuong_id" value="@Model.xa_phuong_id" />
                <input type="hidden" name="todanpho_id" value="@Model.todanpho_id" />
                <input type="hidden" name="system_id" value="@ViewBag.system_id" />
                <input type="hidden" name="quan_huyen_id" value="@ViewBag.quan_huyen_id" />
                <input type="hidden" name="select_status" value="@ViewBag.select_status" />
                <input type="hidden" name="select_option" value="@ViewBag.select_option" />
                <input type="hidden" name="timkiem" value="@ViewBag.timkiem" />
            }
            <div class="module-body">
                @using (Html.BeginForm("EditDslamPort", "DslamPortftth", FormMethod.Post, new { id = "EditDslamPort" }))
                {                      
                    <div align="center">
                        <h3>
                            QUẢN LÝ THÔNG TIN PORT DSLAM - QUANG</h3>
                        @*<div class="account" align="center">
                            <img src="@Url.Content("~/Content/Body/Images/Body_Images/Edit_Device.png")" width="12%" />
                        </div>*@
                    </div>                    
                    if (TempData["msg"] != null)
                    {                            
                    <span class="notification n-error">@TempData["msg"]</span>
                    }
                    if (TempData["error"] != null)
                    {                            
                    <span class="notification n-error">@TempData["error"]</span>
                    } 
                    <br />
                    <br />
                    <table>
                        <div style="width: 50%; padding-left: 35%; float: left">
                            @Html.HiddenFor(model => model.cong)
                            <b>Cổng:</b> <b>@Html.DisplayTextFor(model => model.cong)</b>&nbsp;(
                            @if (Model.status == "0")
                            {
                                <b>Trống</b>
                            }
                            @if (Model.status == "1")
                            {
                                <b>Đã sử dụng</b>
                            }
                            @if (Model.status == "2")
                            {
                                <b>Hỏng</b>
                            }
                            )
                            <br />
                            <br />
                            Mã khách hàng:
                            @Html.TextBoxFor(model => model.ma_kh, new { style = "width:38.9%" })
                            <br />
                            Tên khách hàng:<br>
                            @Html.TextBoxFor(model => model.ten_kh, new { style = "width:300px;" })
                            @*<font color="red">(*)</font>
                            <label style="width: 56%; text-align: left; color: red">
                                @Html.ValidationMessageFor(model => model.ten_kh)
                            </label>*@
                            <br />
                            <br />
                            Địa chỉ:<br>
                            @Html.TextAreaFor(model => model.diachi_kh, new { rows = 2, @class = "input-long" })
                            @*<font color="red">(*)</font>
                            <label style="width: 56%; text-align: left; color: red">
                                @Html.ValidationMessageFor(model => model.diachi_kh)
                            </label>*@
                            <br>
                            <p>
                                <div>
                                    Account Internet: @Html.TextBoxFor(model => model.account_int, new { style = "width:28%" })
                                </div>
                            </p>
                            <p>
                                <div>
                                    Gói DV Internet: @Html.TextBoxFor(model => model.goidv_int, new { style = "width:28.5%" })
                                    
                                </div>
                            </p>
                            <p>
                                <div>
                                    Hình thức Internet:
                                    <select name="hinh_thuc_int"  style="width:27%">
                                        <option value="1"  @(Model.hinh_thuc_int == "1" ? "selected" : "")>Trọn gói</option>
                                        <option value="0" @(Model.hinh_thuc_int == "0" ? "selected" : "")>Lưu lượng</option>
                                    </select>
                                </div>
                            </p>
                            <p>
                                <div>
                                    Trạng thái Internet:
                                    <select name="trang_thai_int"  style="width:27%">
                                        <option value="1" @(Model.trang_thai_int == "1" ? "selected" : "")>Hoạt động</option>
                                        <option value="0" @(Model.trang_thai_int == "0" ? "selected" : "")>Khóa</option>
                                        <option value="2" @(Model.trang_thai_int == "2" ? "selected" : "")>Tạm ngưng</option>
                                    </select>
                                </div>
                            </p>
                            <p>
                                <div>
                                    Account Mytv: @Html.TextBoxFor(model => model.account_mytv, new { style = "width:30.8%" })
                                </div>
                            </p>
                            <p>
                                <div>
                                    Gói DV Mytv: @Html.TextBoxFor(model => model.goidv_mytv, new { style = "width:31.5%" })
                                </div>
                            </p>
                            <br>
                            Đơn vị:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                            @if (ViewBag.donvi != null)
                            {                               
                                @Html.DropDownList("quan_huyen_id", ViewBag.donvi as SelectList, "---Chọn đơn vị---", new { @disabled = "disabled", style = "width: 39%" })                               
                            }
                            <br>
                            Xã phường:&nbsp;
                            @if (ViewBag.khuvuc == null)
                            {    
                                @Html.DropDownList("xa_phuong_id", Enumerable.Empty<SelectListItem>(), "---Chọn Xã phường---", new { @disabled = "disabled", style = "width: 39%" })
                            }
                            else
                            {
                                @Html.DropDownList("xa_phuong_id", ViewBag.khuvuc as SelectList, "---Chọn Xã phường---", new { @disabled = "disabled", style = "width: 39%" })
                            }
                            <br>
                            Tổ dân phố:&nbsp;
                            @if (ViewBag.todanpho == null)
                            {    
                                @Html.DropDownList("todanpho_id", Enumerable.Empty<SelectListItem>(), "---Chọn Tổ dân phố---", new { @disabled = "disabled", style = "width: 38.5%" })
                            }
                            else
                            {
                                @Html.DropDownList("todanpho_id", ViewBag.todanpho as SelectList, "---Chọn Tổ dân phố---", new { @disabled = "disabled", style = "width: 38.5%" })
                            }
                            <br>
                            Dslam:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                            @if (ViewBag.dslam == null)
                            {    
                                @Html.DropDownList("system_id", Enumerable.Empty<SelectListItem>(), "---Chọn Dslam---", new { @disabled = "disabled", style = "width: 38.5%" })
                            }
                            else
                            {
                                @Html.DropDownList("system_id", ViewBag.dslam as SelectList, "---Chọn Dslam---", new { @disabled = "disabled", style = "width: 38.5%" })
                            }
                            <br>
                            <input type="checkbox" value="1" name="dc_checkbox" id="dc_checkbox"  @(Model.status == "0" ? "disabled" : "") onclick="check()"/>&nbsp;Đổi
                            cổng:
                            @if (ViewBag.congtrong == null)
                            {    
                                @Html.DropDownList("congtrong", Enumerable.Empty<SelectListItem>(), "---Chọn Cổng---", new { @disabled = "disabled", style = "width: 39%" })
                            }
                            else
                            {
                                @Html.DropDownList("congtrong", ViewBag.congtrong as SelectList, "---Chọn Cổng---", new { @disabled = "disabled", style = "width: 39%" })
                            }
                            <br>
                            @*Rack: @Html.TextBoxFor(model => model.rackid, new { style = "width:20px;" }) Seft:
                            @Html.TextBoxFor(model => model.selfid, new { style = "width:20px;" })
                            <br>*@ @*Slot/Port:&nbsp;&nbsp;&nbsp;@Html.TextBoxFor(model => model.slot, new { style = "width:20px;" })
                            / @Html.TextBoxFor(model => model.port, new { style = "width:20px;" })
                            <br>
                            Vpi/Vci:&nbsp;&nbsp;&nbsp;&nbsp; @Html.TextBoxFor(model => model.vpi, new { style = "width:20px;" })
                            / @Html.TextBoxFor(model => model.vci, new { style = "width:20px;" })
                            <br>*@
                            <p>
                                <div>
                                    <input type="hidden" name="sm_type" id="sm_type" />
                                    @if (Model.status != "2")
                                    {
                                        <input class="submit-green" onclick="check_form()" type="button" id="sm1" name="sm1"
                                            value="Cập nhật" />                                    
                                        <input class="submit-gray" type="reset" value="Hủy" />                                    
@*<input class="submit-green" type="button" id="sm3" name="sm3" value="Để trống" />
                                        <input class="submit-green" type="button" id="sm2" name="sm2" value="Báo hỏng" />*@
                                    }
                                </div>
                            </p>
                            @*</div>*@
                            <input type="hidden" name="select_status" value="@ViewBag.select_status" />
                            <input type="hidden" name="select_option" value="@ViewBag.select_option" />
                            <input type="hidden" name="timkiem" value="@ViewBag.timkiem" />
                            @Html.HiddenFor(model => model.system_id)
                            @*@Html.HiddenFor(model => model.ma_kh)*@
                            @*@Html.HiddenFor(model => model.trang_thai_int)*@
                            @Html.HiddenFor(model => model.ip_tinh)
                            @*@Html.HiddenFor(model => model.hinh_thuc_int)*@
                            @Html.HiddenFor(model => model.ngay_dk_int)
                            @Html.HiddenFor(model => model.bras_ip)
                            @Html.HiddenFor(model => model.status)
                            @*<input type="hidden" name="slot_old" id="slot_old" value="@Model.slot" />
                            <input type="hidden" name="port_old" id="port_old" value="@Model.port" />*@
                            <input type="hidden" name="system_old" id="system_old" value="@Model.system_id" />
                            <input type="hidden" name="cong_old" id="cong_old" value="@Model.cong" />
                        </div>
                    </table>                   
                }
            </div>
            <!-- End .module-body -->
        </div>
        <!-- End .module -->
        <div style="clear: both;">
        </div>
    </div>
    <!-- End .grid_12 -->
    <div style="clear: both;">
    </div>
</div>
<script>
    function check() {
        if (document.getElementById("dc_checkbox").checked) {
            document.getElementById('quan_huyen_id').disabled = false;
            document.getElementById('xa_phuong_id').disabled = false;
            document.getElementById('todanpho_id').disabled = false;
            document.getElementById('system_id').disabled = false;
            document.getElementById('congtrong').disabled = false;
        }
        else {
            document.getElementById('quan_huyen_id').disabled = true;
            document.getElementById('xa_phuong_id').disabled = true;
            document.getElementById('todanpho_id').disabled = true;
            document.getElementById('system_id').disabled = true;
            document.getElementById('congtrong').disabled = true;
        }
    }
    $('#sm1').click(function () {
        document.getElementById('sm_type').value = "cn";
        if ($("#system_id").val().length == 0) {
            alert("Phai chon DSLAM");
            return;
        }
        if (document.getElementById('congtrong').disabled == false && $("#congtrong").val().length == 0) {
            alert("Phai chon cong trong");
            return;
        }
        //        if ($("#xa_phuong_id").val().length == 0) {
        //            alert("Phai chon khu vuc");
        //            return;
        //        }
        //        if ($("#todanpho_id").val().length == 0) {
        //            alert("Phai chon to dan pho");
        //            return;
        //        }
        if (document.getElementById('ten_kh').value == "") {
            alert("Ten khach hang khong duoc de trong");
            return;
        }
        if (document.getElementById('diachi_kh').value == "") {
            alert("Dia chi khach hang khong duoc de trong");
            return;
        }
        if (document.getElementById('account_int').value == "" && document.getElementById('account_mytv').value == "") {
            alert("Phai nhap account internet hoac mytv");
            return;
        }
        $('system_id').removeAttr('disabled');
        document.getElementById("EditDslamPort").submit();
    });
    $('#sm2').click(function () {
        document.getElementById('sm_type').value = "bh";
        document.getElementById("EditDslamPort").submit();
    });
    $('#sm3').click(function () {
        document.getElementById('sm_type').value = "dt";
        document.getElementById("EditDslamPort").submit();
    });    
</script>
<script type="text/javascript">
    $("#quan_huyen_id").change(function () {
        $("#todanpho_id").html("<option value=''>---Chọn Tổ dân phố---</option>");
        $("#congtrong").html("<option value=''>---Chọn cổng---</option>")
        $.ajax({
            type: "POST",
            url: '@Url.Action("getDslamJson", "DslamPortftth")',
            data: { quan_huyen_id: $("#quan_huyen_id > option:selected").attr("value"), Order: "name" },
            success: function (data) {
                var items = [];
                items.push("<option value=''>---Chọn Dslam---</option>");
                $.each(data, function () {
                    items.push("<option value='" + this.Value + "'>" + this.Text + "</option>");
                });
                $("#system_id").html(items.join(' '));
            }
        })
    });
    $("#quan_huyen_id").change(function () {
        $.ajax({
            type: "POST",
            url: '@Url.Action("getKhuvucJson", "DslamPortftth")',
            data: { quan_huyen_id: $("#quan_huyen_id > option:selected").attr("value"), Order: "ten" },
            success: function (data) {
                var items = [];
                items.push("<option value=''>---Chọn Xã phường---</option>");
                $.each(data, function () {
                    items.push("<option value='" + this.Value + "'>" + this.Text + "</option>");
                });
                $("#xa_phuong_id").html(items.join(' '));
            }
        })
    });
    $("#xa_phuong_id").change(function () {
        $("#system_id").html("<option value=''>---Chọn Dslam---</option>");
        $("#congtrong").html("<option value=''>---Chọn cổng---</option>")
        $.ajax({
            type: "POST",
            url: '@Url.Action("getTodanphoJson", "DslamPortftth")',
            data: { xa_phuong_id: $("#xa_phuong_id > option:selected").attr("value"), Order: "ten" },
            success: function (data) {
                var items = [];
                items.push("<option value=''>---Chọn Tổ dân phố---</option>");
                $.each(data, function () {
                    items.push("<option value='" + this.Value + "'>" + this.Text + "</option>");
                });
                $("#todanpho_id").html(items.join(' '));
            }
        })
    });
    $("#xa_phuong_id").change(function () {
        $.ajax({
            type: "POST",
            url: '@Url.Action("getDslamByKhuvucJson", "DslamPortftth")',
            data: { xa_phuong_id: $("#xa_phuong_id > option:selected").attr("value"), Order: "name" },
            success: function (data) {
                var items = [];
                items.push("<option value=''>---Chọn Dslam---</option>");
                $.each(data, function () {
                    items.push("<option value='" + this.Value + "'>" + this.Text + "</option>");
                });
                $("#system_id").html(items.join(' '));
            }
        })
    });
    $("#todanpho_id").change(function () {
        $("#congtrong").html("<option value=''>---Chọn cổng---</option>")
        $.ajax({
            type: "POST",
            url: '@Url.Action("getDslamByTodanphoJson", "DslamPortftth")',
            data: { todanpho_id: $("#todanpho_id > option:selected").attr("value"), Order: "name" },
            success: function (data) {
                var items = [];
                items.push("<option value=''>---Chọn Dslam---</option>");
                $.each(data, function () {
                    items.push("<option value='" + this.Value + "'>" + this.Text + "</option>");
                });
                $("#system_id").html(items.join(' '));
            }
        })
    });

    $("#system_id").change(function () {
        $.ajax({
            type: "POST",
            url: '@Url.Action("getCongtrongJson", "DslamPortftth")',
            data: { system_id: $("#system_id > option:selected").attr("value"), system_id_old: document.getElementById('system_old').value, cong: document.getElementById('cong').value, Order: "cong" },
            success: function (data) {
                var items = [];
                items.push("<option value=''>---Chọn cổng---</option>");
                $.each(data, function () {
                    items.push("<option value='" + this.Value + "'>" + this.Text + "</option>");
                });
                $("#congtrong").html(items.join(' '));
            }
        })
    });
</script>
<!-- End .container_12 -->
